﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Douban.Modules.Conversation.ViewModels;

namespace Douban.Modules.Conversation.Views
{
    /// <summary>
    /// ConversationWorkSpaceView.xaml 的交互逻辑
    /// </summary>
    public partial class ConversationWorkSpaceView : IConversationWorkSpaceView
    {
        public ConversationWorkSpaceView()
        {
            InitializeComponent();
        }

        #region IConversationWorkSpaceView Members

        public IConversationWorkSpaceViewModel Context
        {
            get
            {
                return this.DataContext as IConversationWorkSpaceViewModel;
            }
            set
            {
                this.DataContext = value;
            }
        }

        public void SetMessageReaderScrollToBottom()
        {
            MessageReaderScrollViewer.ScrollToBottom();
        }

        public void ClearMessageSenderTextBox()
        {
            MessageSenderTextBox.Text = String.Empty;
        }

        public event KeyEventHandler SendMessageKeyDown;

        #endregion

        private void ConversationWorkSpaceView_Loaded(object sender, RoutedEventArgs e)
        {
            MessageSenderTextBox.Focus();
        }

        private void MessageSenderTextBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (SendMessageKeyDown != null)
                SendMessageKeyDown(sender, e);

            if (e.Key == Key.Enter && !String.IsNullOrEmpty(MessageSenderTextBox.Text))
            {
                MessageSenderTextBox.Text += "\n";
                MessageSenderTextBox.Select(MessageSenderTextBox.Text.Length, 0);
            }
        }
    }
}
